package com.yrd.common.webui;

import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;


public class EventSocket extends WebSocketAdapter
{
    @Override
    public void onWebSocketConnect(Session session)
    {
        super.onWebSocketConnect(session);
        System.out.println("Socket Connected: " + session);
        HttpEngine.getInstance().add(this);
    }
    
    @Override
    public void onWebSocketText(String message)
    {
        super.onWebSocketText(message);
        System.out.println("Received TEXT message: " + message);
        HttpEngine.getInstance().sendMessage("收到："+message);
    }
    
    @Override
    public void onWebSocketClose(int statusCode, String reason)
    {
        super.onWebSocketClose(statusCode,reason);
        System.out.println("Socket Closed: [" + statusCode + "] " + reason);
        HttpEngine.getInstance().remove(this);
    }
    
    @Override
    public void onWebSocketError(Throwable cause)
    {
        super.onWebSocketError(cause);
        cause.printStackTrace(System.err);
    }
}
